<?php
//error_reporting(E_ALL^E_NOTICE);
require '../../config/config.php';
session_start();
if(empty($_SESSION['member'])){
	echo "<script>location='../index.php';</script>";
}
$bnoRs=mysqli_fetch_array(mysqli_query($con,"select * from bond where user='".$_SESSION['member']."'"));
if($bnoRs['orderNumber']==""){
    echo "<script>location='../add-job.php';</script>";
}
function request_post($url = '', $post_data = array())
{
    if (empty($url) || empty($post_data)) {
        return false;
    }
    $o = "";
    foreach ($post_data as $k => $v) {
        $o .= "$k=" . urlencode($v) . "&";
    }
    $post_data = substr($o, 0, -1);
    $postUrl = $url;
    $curlPost = $post_data;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $postUrl);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
$url = ''; //官方支付网关，用于官方系统订单生成，请勿修改！暂不对外提供服务
$post_data['AppId'] = ''; //请输入你的AppId
$post_data['AppKey'] = ''; //请输入你的AppKey
$post_data['out_trade_no'] = $bnoRs['orderNumber']; //请输入商家订单号，也就是你系统的订单号。
$post_data['subject'] = $_SESSION['member']."商户保证金"; //请输入订单名称
$post_data['total_amount']  = $bnoRs['amount']; //请输入订单金额
$res = request_post($url, $post_data);
if ($res=="") {
    echo "System erro!<br />0x000001<br />系统异常，暂时无法继续完成支付！请联系email：sdrzlyl@petalmail.com！<br /><br />";
    //var_dump($post_data);
} else {
    //var_dump($res);
    $res = substr($res, 27); //截取返回订单号，如果订单号出现异常，请调整此处！默认值为：27
    $payGateway = ""; //官方支付网关，用于进行支付处理，请勿修改！暂不对外提供服务
    //echo "<br /><a href='" . $payGateway . "?orderNo=" . $res . "'>立即支付</a>";
    echo "<script>location='" . $payGateway . "?orderNo=" . $res . "';</script>";
}